package demo;
import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;

import demo.ssh.dao.TestDao;
import demo.ssh.dao.TestDaoImpl;
import demo.ssh.model.User;
import demo.ssh.service.TestService;

public class AppMain {
	 
	User user;
	public static void main(String[] args) {
		testWeb();
	}
	public static void t1(){
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml"); 
		TestDao dao = (TestDao) applicationContext.getBean("testDao");
//		System.out.println(dao.getSessionFactory());
		dao.getUser(1); 
		User u2=new User();
		u2.setName("Jack");
		dao.saveUser(u2);
	}
	public static void t2(){
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContextTx.xml"); 
		TestDao dao = (TestDao) applicationContext.getBean("userDaoTarget");
		dao.getUser(1); 
		User u2=new User();
		u2.setName("Jack11");
		dao.saveUser(u2);
	}
	public static void t3(){
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContextAnnotation.xml"); 
		TestDao dao = (TestDao) applicationContext.getBean("daoImpl");
		dao.getUser(1); 
		User u2=new User();
		u2.setName("Jack annotation");
		dao.saveUser(u2);
	}
	public static void t4(){
		ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContextAnnotation.xml"); 
		TestService service = (TestService) applicationContext.getBean("service");
		service.servce();
	}
	public static void testWeb(){
		ApplicationContext applicationContext = new FileSystemXmlApplicationContext("WebContent/WEB-INF/applicationContext.xml"); 
		TestService service = (TestService) applicationContext.getBean("service");
		service.servce();
	}
}
